/**       
 * @{#} BaseObjectPool.java Create on 2012-3-29 下午12:25:39       
 *       
 * Copyright (c) 2012 by able.       
 */
package __javable.core.util.pool;

/** 
 *  
 * 
 * @history 
 * <PRE> 
 * --------------------------------------------------------- 
 * VERSION       DATE            BY       CHANGE/COMMENT 
 * --------------------------------------------------------- 
 * 1.0           2012-3-29      able         create 
 * --------------------------------------------------------- 
 * </PRE> 
 * 
 */
public abstract class BaseObjectPool<T> implements ObjectPool<T> {
	
	@Override
    public abstract T borrowObject() throws Exception;
	
    @Override
    public abstract void returnObject(T obj) throws Exception;
    
    @Override
    public abstract void invalidateObject(T obj) throws Exception;
    
    @Override
    public int getNumIdle() throws UnsupportedOperationException {
        return -1;
    }
    
    @Override
    public int getNumActive() throws UnsupportedOperationException {
        return -1;
    }
    
    @Override
    public void clear() throws Exception, UnsupportedOperationException {
        throw new UnsupportedOperationException();
    }
    
    @Override
    public void addObject() throws Exception, UnsupportedOperationException {
        throw new UnsupportedOperationException();
    }
    
    @Override
    public void close() throws Exception {
        closed = true;
    }
    
    public final boolean isClosed() {
        return closed;
    }
    
    protected final void assertOpen() throws IllegalStateException {
        if (isClosed()) {
            throw new IllegalStateException("Pool not open");
        }
    }

    /** Whether or not the pool is closed */
    private volatile boolean closed = false;
}
